import { Component, OnInit, ViewChild, ViewEncapsulation, NgZone } from '@angular/core';
import { I18nService } from '../../core/i18n/i18n.service';
import { DialogConfig, DialogComponent, DialogService, RatingConfig } from 'ngx-weui';
import { ApiService } from 'src/app/core/api';
import { Router, ActivatedRoute } from '@angular/router';
import { MessageService } from 'src/app/core/message.service';
import { StorageService } from 'src/app/core/sotrage/storage.service';

@Component({
	templateUrl: './index.component.html',
	styleUrls: ['./index.component.less'],
})
export class GuideComponent implements OnInit {
	list: Array<any>=[];
	user: any = null;
	customIconsAndClassCog: RatingConfig = {
		max:5,
		stateOff: 'off',
		stateOn: 'on',
		cls: 'rating'
	}
	pageData = {
		pageNo: "1",
		pages: "1",
		genre01Id: '1' ,
		genre02Id: '' ,
		gameName: "", //# 游戏名称
		providerId:''
	}
	lang = this.sto.get('lang')?this.sto.get('lang'):'zh';
	constructor(
		private message: MessageService,
		private router: Router,
		private api: ApiService,
		private sto: StorageService
	) {
		this.message.sendMessage('fl');
		this.user = this.sto.get('user');
	}
	ngOnInit() {
		this.getMenu('2' , this.pageData);
	}
	onSel(tegId) {
		this.api.post('开始游戏', {id:tegId}).then(res => {
			this.router.navigate(['/gz'], {
				queryParams: res['data']
			});
		})
	}
	gamePlaysTitle;
	gamePlaysTitleMap={
		'':'TOP 10',
		'1':'新上架',
		'2':'热 门',
		'3':'角色扮演',
		'4':'策 略',
		'5':'对 战',
		'6':'动 作',
		'7':'自 由',
		'8':'其 它',
		'9':'C P'
	};
	isClick = true;
	onChangeTab(bool) {
		this.isClick = bool;
		this.pageData.pages = '1';
		this.pageData.genre01Id = bool ? '1' : '2';
		this.getList();
	}
	search(){
		// this.pageData.gameName='';
		this.getList();
	}
	searchClear(){
		this.pageData.gameName='';
		this.getList();
	}
	getList() {
		this.pageData.providerId = '';
		this.api.post('游戏列表', this.pageData).then(res => {
			this.pageData.pageNo = res['data']['pageNo'];
			this.pageData.pages = res['data']['pages'] == 0 ? 1 : res['data']['pages'];
			let lists = res['data']['list'];
			if(res['data']['pageNo'] == 1){
				this.list = lists;
			}else{
				for (let i = 0; i < lists.length; i++) {
					this.list.push(lists[i]);
				}
			}
		}).catch(res => {
			return res;
		});
	}
	getProviderList() {
		let data = this.pageData;
		data.genre02Id ='';
		this.api.post('游戏列表', data).then(res => {
			this.pageData.genre02Id = '99999';
			let lists = res['data']['list'];
			if(res['data']['pageNo'] == 1){
				this.list = lists;
			}else{
				for (let i = 0; i < lists.length; i++) {
					this.list.push(lists[i]);
				}
			}
		}).catch(res => {
			return res;
		});
	}
	providerlist=[];
	selProvider;
	gameProviderList() {
		this.api.post('游戏提供商列表', this.gameProviderPage).then(res => {
			let lists = res['data']['list'];
			this.providerlist = lists;
			this.selProvider = this.providerlist[0];
			this.pageData.providerId = this.selProvider.id;
			this.getList();
		}).catch(res => {
			return res;
		});
	}
	menus=[];
	getMenu(key, data){
		this.api.post('获取游戏子类列表', data).then(res => {
			switch (key) {
				case '1':
					
					break;
				case '2':
					this.menus = res['data']['gameGenre'];
					this.menus.push({id: 99999, name: '{"ja_JP":"CP","en_US":"CP","zh_CN":"CP"}', icon: "http://47.245.33.7:8213/game/genre/i10.png"});
					this.pageData.genre02Id = this.menus[0]['id'];
					this.selMenu = this.menus[0];
					this.gamePlaysTitle = this.selMenu.name;
					this.getList();
					break;
			}
		}).catch(res => {
			return res;
		});
	}
	gameProviderPage = {pageNo:1};
	iscpClick = true;
	onClick(item) {
		this.pageData.genre02Id = item.id;
		this.gamePlaysTitle = item.name;
		if ( item.id === 99999) {
			this.gameProviderList();
		} else {
			this.getList();
		}
	}
	selMenu;
	onProviderClick(item){
		this.selProvider = item;
		this.pageData.providerId = item.id;
		this.getProviderList();
	}
}
